﻿// JScript 文件

String.prototype.trim   =   function(){   
    return   this.replace(/(^\s*)|(\s*$)/g,"");   
} 
String.prototype.IsInt=function() 
{ 
    if(this=="NaN") return false; 
        return this==parseInt(this).toString(); 
} 
function   isNumeric(v){   
  return   typeof(v)=="number"   
}  

///判断是否是正确的手机号码
function checkMobile(input){
    var mobile = input;
     //电信天翼手机
     var reg1 = /^133\d{8}$/; 
     var reg2 = /^153\d{8}$/;
     var reg3 = /^189\d{8}$/;
     var reg3 = /^187\d{8}$/;
     //移动
     var reg3 = /^1340\d{7}$/;
     var reg4 = /^1341\d{7}$/;
     var reg5 = /^1342\d{7}$/;
     var reg6 = /^1343\d{7}$/;
     var reg7 = /^1344\d{7}$/;
     var reg8 = /^1345\d{7}$/;
     var reg9 = /^1346\d{7}$/;
     var reg10 = /^1347\d{7}$/;
     var reg11 = /^1348\d{7}$/;
     var reg12 = /^135\d{8}$/;
     var reg13 = /^136\d{8}$/;
     var reg14 = /^137\d{8}$/;
     var reg15 = /^138\d{8}$/;
     var reg16 = /^139\d{8}$/;
     var reg17 = /^150\d{8}$/;
     var reg18 = /^151\d{8}$/;
     var reg19 = /^157\d{8}$/;
     var reg20 = /^158\d{8}$/;
     var reg21 = /^159\d{8}$/;
     //移动3G号段
     var reg22 = /^188\d{8}$/;
     var reg30 = /^189\d{8}$/;
     //联通号段
     var reg23 = /^130\d{8}$/;
     var reg24 = /^131\d{8}$/;
     var reg25 = /^132\d{8}$/;
     var reg26 = /^156\d{8}$/;
     var reg27 = /^1349\d{8}$/;
        
     var my=false; 
     if (reg1.test(mobile))my=true; 
     if (reg2.test(mobile))my=true;
     if (reg3.test(mobile)) my = true;
     if (reg4.test(mobile)) my = true;
     if (reg5.test(mobile)) my = true;
     if (reg6.test(mobile)) my = true;
     if (reg7.test(mobile)) my = true;
     if (reg8.test(mobile)) my = true;
     if (reg9.test(mobile)) my = true;
     if (reg10.test(mobile)) my = true;
     if (reg11.test(mobile)) my = true;
     if (reg12.test(mobile)) my = true;
     if (reg13.test(mobile)) my = true;
     if (reg14.test(mobile)) my = true;
     if (reg15.test(mobile)) my = true;
     if (reg16.test(mobile)) my = true;
     if (reg17.test(mobile)) my = true;
     if (reg18.test(mobile)) my = true;
     if (reg19.test(mobile)) my = true;
     if (reg20.test(mobile)) my = true;
     if (reg21.test(mobile)) my = true;
     if (reg22.test(mobile)) my = true;
     if (reg23.test(mobile)) my = true;
     if (reg24.test(mobile)) my = true;
     if (reg25.test(mobile)) my = true;
     if (reg26.test(mobile)) my = true;
     if (reg27.test(mobile)) my = true;
     if (reg30.test(mobile)) my = true;
     
     if (!my){ 
        return false;
     }else{ 
        return true;
     } 
} 


//验证事件 this.tb_Mobile.Attributes.Add("onblur", "select_onblur()");
function select_onblur()
{
    var flag = false;
    var text1 = document.getElementById('tb_Mobile');
    var spanforerror = document.getElementById('spanforError');
        
    if(tb_Mobile_IsNull(text1))
    {
        spanforerror.innerHTML = "<span style='color:red; font-weight:bold'>请选择或填写至少一个手机号码</span>";
    }
    
    if(text1.value.length >0)
    {
        var arraryText1 = text1.value.trim().split(',');
        for(var i =0;i<arraryText1.length;i++)
        {
            if(arraryText1[i].length >0)
            {
                if(arraryText1[i].length != 11)
                {
                    spanforerror.innerHTML = "<span style='color:red; font-weight:bold'>号码\"" + arraryText1[i] + "\"不是有效的手机号码！</span>";
                    flag = false;
                    break;
                }
                if(!checkMobile(arraryText1[i]))
                {
                    flag = false;
                    spanforerror.innerHTML = "<span style='color:red; font-weight:bold'>号码\"" + arraryText1[i] + "\"不是有效的手机号码！</span>";
                    break;
                }
                spanforerror.innerHTML = "";
                flag = true;
                continue;
            }
        }
    }
    
    return flag;
}


///双击事件 ListBox1.Attributes.Add("ondblclick", "select1_ondblclick()");
function select1_ondblclick() {
    var TextBox1 = document.getElementById('tb_Mobile');
    var ListBox1 = document.getElementById('ListBox1');
    var str = ListBox1.options[ListBox1.selectedIndex].value + ',';
    if(TextBox1.value.indexOf(str)>=0)
    {
    
    }
    else
    {
        TextBox1.value += str;
    }
}

///判断发送的短信内容是否为空
function tb_MsgContent_IsNull()
{
    var tb_MsgContent = document.getElementById('tb_MsgContent');
    var text = tb_MsgContent.value;    
    var textValue = text.replace(/(^\s*)|(\s*$)/g, "");     //替换输入内容当中所有的空字符，包括全角空格，半    
    if(textValue==null || textValue=="") {    
         //alert("输入的内容为空，无法查询！");    
        return false;    
    }
    else
    {
        return true;
    }
}
function tb_Mobile_IsNull(obj)
{
    //var tb_MsgContent = document.getElementById(obj);
    var text = obj.value;    
    var textValue = text.replace(/(^\s*)|(\s*$)/g, "");     //替换输入内容当中所有的空字符，包括全角空格，半    
    if(textValue==null || textValue=="") {    
         //alert("输入的内容为空，无法查询！");    
        return true;    
    }
    else
    {
        return false;
    }
}


function btnAddContact_Click()
{
    var cb = document.getElementById('cb_SelectAll');
    var btnadd = document.getElementById('btn_AddContact');
    var spanforerror = document.getElementById('spanforError');
    var selectforContacts = document.getElementById('ListBox1');
    var tb_Mobile = document.getElementById('tb_Mobile');
    
    if(cb.checked == true)
    {
        spanforerror.innerHTML = "";
//        for(var i = 0;i<selectforContacts.options.length;i++)
//        {
//            tb_Mobile.value +=selectforContacts.options[i].value + ',';
//        }
    }
    else
    {
//        int i = selectforContacts.selectedIndex;
//        tb_Mobile.value +=selectforContacts.options[i] + ',';
    }
}